<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>表白墙2</title>
</head>
<body>
    <div class="container">
        
        <h1>表白墙</h1>
        <p>输入后点击提交，会将信息显示在表格中</p>
        <!-- <span class="one">输入后点击提交，会将信息显示在表格中</span> -->

        <div class="row">
            <span>谁: </span>
            <input type="text" class="input">
        </div>
        <div class="row">
            <span>对谁: </span>
            <input type="text" class="input">
        </div>
        <div class="row">
            <span>说什么: </span>
            <input type="text" class="input">
        </div>
        <div class="row">
            <input type="button" value="提交" class="submit">
        </div>


    </div>

    <script>
    // 1.获取元素
    // 2.根据元素获取输入，构造新的元素
    // 3.将构造含的元素添加
    // 4.清空之前表格内容
    var submit = document.querySelector('.submit');
    submit.onclick = function() {
        var inputs = document.querySelectorAll(".input");
        var from = inputs[0].value;
        var to = inputs[1].value;
        var message = inputs[2].value;
        console.log(from +","+to+","+message);
        if(from=='' || to=='' || message==''){
            return;
        }

        // 2. 构造html元素
        var row = document.createElement('div');
        row.className = 'row';
        row.innerHTML = from +","+to+","+ message;
        // 3. 把构造好的元素添加进去
        var container = document.querySelector(".container");
        container.appendChild(row);
        // 4. 同时清理之前输入框的内容
        for (var i=0 ;i<3; i++){
            inputs[i].value = '';
        }
    }


    </script>



    <style>
        * {
            margin: 0;
            padding: 0;
        }

        h1 {
            text-align: center;
            padding: 20px 0;
        }

        span {
            width: 100px;
            line-height: 40px;
        }

        .row {
            height: 40px;
            display: flex;
            justify-content: center;
            align-items: center;
            margin: 10px;
        }

        /* .one {
            font-size: 14px;
            color: #666;
            text-align: center;
            padding: 10px 0;
        } */
        p {
            font-size: 14px;
            color: #666;
            text-align: center;
            padding: 10px 0;
        }

        .submit {
            height: 50px; 
            width: 380px; 
            color: white;
            background-color: orange;
            font-size: 20px;
            border-radius: 10px;
            margin-top: 50px;
            margin-bottom: 30px;
        }

        .container {
            width: 400px;
            /* text-align: center; */
            margin: 0 auto;
            
        }

        .input {
            width: 200px;
            height: 30px;
            margin: 5px;
            border-radius: 5px;
        }

    </style>

    
</body>
</html>